package com.situ.gym.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.situ.gym.pojo.User;
import com.situ.gym.mapper.UserMapper;
import com.situ.gym.pojo.query.UserQuery;
import com.situ.gym.pojo.vo.DayCountVO;
import com.situ.gym.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.situ.gym.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Guan
 * @since 2025-08-28
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public IPage<User> list(UserQuery userQuery) {
        Map<String, Object> map = ThreadLocalUtil.get();//如果有需要，通过ThreadLocalUtil可以在三层架构（同一线程内的任何位置）用线程获取token(解析后包含用户信息)
        IPage<User> page = new Page<>(userQuery.getPage(),userQuery.getLimit());//1创建一个分页对象，用于 MyBatis-Plus 的分页查询。getPage()获取当前页，getLimit())获取每页多少行
        return userMapper.list(page,userQuery);//// 2. 调用Mapper方法，传入分页对象和查询条件
    }

    @Override
    public User selectByName(String name) {
        return userMapper.selectByName(name);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        userMapper.deleteAll(ids);
    }

    @Override
    public List<DayCountVO> selectUserCount(Date date) {
        return userMapper.selectUserCount(date);
    }
}
